﻿using DG.Tweening;
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace PickMeUp
{
    public class FireFightingTruck : MonoBehaviour
    {
        [SerializeField, Title("消防车音效")] private AudioSource fireTruckAudio;

        [SerializeField, Title("消防车")] private Transform fireTruckTransform;

        [SerializeField, Title("消防员")] private Transform firemanTransform;


        [SerializeField, Title("消防车火灾路线")] private Vector3[] fireTruckRoute;
        [SerializeField, Title("消防车火灾路线时间")] private float duration;

        [SerializeField, Title("消防车回家路线")] private Vector3[] homeRoute;
        [SerializeField, Title("消防车回家路线时间")] private float homeDuration;

        public bool IsArrivedFire = false;
        public void ShowFireTruck()
        {
            fireTruckTransform.gameObject.SetActive(true);
            PlayAudio();
        }

        public void ShowFireMan()
        {
            firemanTransform.gameObject.SetActive(true);
            GamePlay.Instance.audioControl.PlayLoopAudio("喷水");
        }

        public void HideFireMan()
        {
            firemanTransform.gameObject.SetActive(false);
            GamePlay.Instance.audioControl.TryStopLoopAudio("喷水");
        }

        //去火灾现场
        public void GoToFire()
        {
            transform.DOPath(fireTruckRoute, duration, PathType.Linear)
           .SetEase(Ease.Linear)
           .SetLookAt(0.01f)
           .OnComplete(() => { IsArrivedFire = true; });
        }

        //回基地
        public void GoHome()
        {
            StopAudio();
            transform.DOPath(homeRoute, homeDuration, PathType.Linear)
          .SetEase(Ease.Linear)
           .SetLookAt(0.01f);
        }

        private void PlayAudio()
        {
            //播放音效
            fireTruckAudio.Play();
        }

        private void StopAudio()
        {
            //停止音效
            fireTruckAudio.Stop();
        }
    }
}
